<include file="Template:pageheader"/>

<link rel="stylesheet" type="text/Css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<js href="__PUBLIC__/Js/Function.js" />
<js href="__PUBLIC__/Js/ajaxupload.js" />
<js href="__PUBLIC__/Js/FileController.js" />

<script>
  $(function() {
    $( "#datepicker1" ).datepicker();
    $( "#datepicker2" ).datepicker();
    
	//Upload File
   	var URI         =   "__PUBLIC__/Upload/images/"; 		
   	var button      =   $('#button1'), interval;
   	
   	new AjaxUpload(button, {
   		action: '__APP__/Course/uploadImg', 
   		name: 'userfile',
   		onSubmit : function(file, ext){		
   			button.text('Uploading');
   			this.disable();				
   			// Uploding -> Uploading. -> Uploading...
   			interval = window.setInterval(function(){
   				var text = button.text();
   				if (text.length < 13){
   					button.text(text + '.');					
   				} else {
   					button.text('Uploading');				
   				}
   			}, 200);
   		},
   		onComplete: function(file, response){
   			button.text('Upload');				
   			//set values
   			var img             =   document.getElementById("original_img");
   			var thum_img        =   document.getElementById("thumb_img");
   			var img_1           =   document.getElementById("img1");
   			var valueArr        =   response.split(","); //split string  
   			img.value           =   valueArr[0];
   			img_1.src           =   URI + img.value;//将照片地址赋给img元素
   			img_1.style.display =   "block";
   			thum_img.value      =   valueArr[1];
   			//show action delete
   			var delimg1         =   document.getElementById("delimg1");
   			delimg1.style.display = "block";
   			// clear 定时器
   			window.clearInterval(interval);
   			this.enable();						
   		}
   	});
   	//add code here   	
  });  
  
  
  FileController.init("__APP__/File/deleteAdImgAndRecord");
  
  FileController.deleteImg = function(_id1,_id2){
	    var obj_1      =    document.getElementById(_id1);
	  	var obj_2      =    document.getElementById(_id2);		
	  	var id         =    document.getElementById("ad_id");		
	  	var datas      =    {};
	  	datas['img1']  =    obj_1.value;
	  	datas['img2']  =    obj_2.value;
	  	datas['id']    =    id.value;
	  	//请求服务器
	  	$.extend(FileController.opt,{
	  		data:datas,
	  		url:FileController.url,
	  		success:function(msg){
	  			if(msg.data == "1"){
	  				var img            =   null;
	  				var act_del        =   null;
	  				if(_id1 == 'original_img'){
	  					img = document.getElementById('img1');
	  					act_del = document.getElementById('delimg1');
	  				}else{
	  					img = document.getElementById('img2');
	  					act_del = document.getElementById('delimg2');
	  				}				
	  				img.src            =   "";
	  				obj_1.value        =   "";
	  				img.style.display  =   "none";
	  				act_del.style.display =  "none";
	  			}
	  		}
	  	});
	  	$.ajax(FileController.opt);
  }
  
</script>

<div class="mauto">
	<form method="post" action="__APP__/Adverse/updateadOk">		
		<table id="mytab" border="1" class="t1" width="100%">
		  <tr>
		    <td align="right" width="30%">{$lang.ad_name}</td>
		    <td align="left"><input type="text" class="input" name="ad_name" value="{$adverse.ad_name}"></td>			
		  </tr>
		  <tr>
	    <td align="right">{$lang.ad_type}</td>
	    <td align="left">
			<select name="ad_type" class="select" value="{$adverse.ad_type}">
				<option value="1">首页</option>
				<option value="2">二级页面</option>
			</select>
		</td>			
	  </tr>
	  <tr>
	    <td align="right">{$lang.ad_content}</td>
	    <td align="left">
			<textarea name="ad_content" class="input" style="height:100px;">{$adverse.ad_content}</textarea>
		</td>			
	  </tr>
	  <tr>
	    <td align="right">{$lang.ad_picture}</td>
	    <td align="left">
			<span>							
				<div id="button1" class="button">Upload</div>	
			</span>
			<span>
				<input id="original_img"  type="hidden" name="ad_img" value="{$adverse.ad_img}"/>
				<input id="thumb_img"  type="hidden"  value=""/>
				<img id="img1" title="{$adverse.ad_img}" style="display:none; width:100px;height:30px;" src="__PUBLIC__/Upload/images/{$adverse.ad_img}"/>						
				<span>
					<a id="delimg1" title="{$adverse.ad_img}" href="javascript:FileController.deleteImg('original_img','thumb_img');" class="hide">{$lang.delete}</a>
				</span>
			</span>
		</td>			    			
	  </tr>
		  <tr>
		    <td align="right">媒体类型{$lang.media_type}</td>
		    <td align="left">
				<select name="media_type" class="select" value="">
					<option value="">请选择类型{$lang.please_select_type}</option>
					<option value="1">图片</option>
					<option value="2">flash</option>
					<option value="3">文字</option>
				</select>
			</td>			
		  </tr>
		  <tr>
		    <td align="right">广告位置{$lang.ad_position}</td>
		    <td align="left"><input type="text" class="input" name="position" value="{$adverse.position}"/></td>			
		  </tr>
		  <tr>
		    <td align="right">开始时间{$lang.start_time}</td>
		    <td align="left"><input type="text" class="input" name="start_time"  id="datepicker1" value="{$adverse.start_time}"/></td>			
		  </tr>
		  <tr>
		    <td align="right">结束时间{$lang.end_time}</td>
		    <td align="left"><input type="text" class="input" name="end_time"  id="datepicker2" value="{$adverse.end_time}"/></td>	
		  </tr>
		  <tr>
		    <td align="right">联系人姓名{$lang.link_man}</td>
		    <td align="left"><input type="text" class="input" name="link_man"  value="{$adverse.link_man}"/></td>			
		  </tr>
		  <tr>
		    <td align="right">联系人电话{$lang.link_phone}</td>
		    <td align="left"><input type="text" class="input" name="link_phone" value="{$adverse.link_phone}"/></td>			
		  </tr>
		  <tr>
		    <td align="right">是否显示{$lang.enabled}</td>
		    <td align="left"><input type="checkbox" name="enabled"/>&nbsp;&nbsp;是</td>		
		  </tr>
		</table>
		<div class="mp50" style="text-align:center;">
	        <input type="hidden" id="ad_id" name="ad_id" value="{$adverse.ad_id}"/>
	        <input type="submit" value="{$lang.submit_text}"/>
	        <input type="reset" value="{$lang.reset_text}"/>
	     </div>							
	</form>		
</div>

<script>
	//处理图片显示问题	
	DisplayOrHide.display('img1','title');
	DisplayOrHide.display('delimg1','title');	
	
	var obj   =  document.getElementById('img1');
	if(obj.title.length == 0){
		obj.src = '';
	}
</script>

<include file="Template:pagefooter"/>


